package com.medvalley.tcm.dao;

import com.medvalley.tcm.domain.Questionnaire;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by LinSong on 2018/3/6.
 */
public interface QuestionnaireDao extends CrudRepository<Questionnaire, Long> {

    List<Questionnaire> getOneByUserNumberAndOrg(String userNumber, String org);

    List<Questionnaire> getOneByUserNumberAndSrcOrderByIdDesc(String userNumber, String src);

    @Modifying
    @Query(nativeQuery = true, value = " replace into t_questionnaire (org,user_number,gender,age,create_time,answer,edition,confirm,is_pinghe,src,tendency) " +
            "values(:org,:userNumber,:gender,:age,:createTime,:answer,:edition,:confirm,:isPinghe,:src,:tendency)")
    int replaceInto(@Param("org") String org, @Param("userNumber") String userNumber, @Param("gender") int gender, @Param("age") int age,
                    @Param("createTime") long createTime, @Param("answer") String answer, @Param("edition") int edition, @Param("confirm") String confrim,
                    @Param("isPinghe") int isPinghe, @Param("src") String src, @Param("tendency") String tendency);

    List<Questionnaire> findAllByUserNumberAndEditionAndOrgAndSrc(String userNumber, int edition, String org, String src, Pageable pageable);

    List<Questionnaire> findAllByUserNumberAndOrgAndSrc(String userNumber, String org, String src, Pageable pageable);


}
